﻿using System;
using System.Collections.Generic;
using ProtoBuf.Message;

namespace UI
{
    public class UIChatMessage
    {
        public int chatType;
        public long senderId;
        public string heroId;
        public string playerName;
        public DateTime time;
        public ChatMessageType messageType;
        public string msgContent;

        public const string pvpReplay = "[pvpReplay]";

        public string icon
        {
            get
            {
                return Dict.Blo.DictHeroBlo.GetTableHero(heroId).iconName;
            }
        }
        public UIChatMessage(SCChatTcp chat)
        {
            this.chatType = chat.chatType;
            senderId = chat.play.playerId;
            heroId = chat.play.heroWarId;
            playerName = chat.play.playerName;
            //senderId = chat.playerId;
            //heroId = chat.playerHeroId;
            //playerName = chat.playerName;
            time = ServerTimerTool.Java2CSTimeLocale(chat.time);
            AnalysMessage(chat.content);
        }
        public void AnalysMessage(string content)
        {
            if (content == null)
            {
                msgContent = string.Empty;
                return;
            }
            if(content.StartsWith(pvpReplay))
            {
                messageType = ChatMessageType.PVP_REPLAY;
                this.msgContent = content.Substring(pvpReplay.Length);
            }
            else
            {
                messageType = ChatMessageType.NORMAL;
                this.msgContent = content;
            }
        }

        public void OnClickHandler()
        {
            switch(messageType)
            {
                case ChatMessageType.NORMAL:

                    break;
                case ChatMessageType.PVP_REPLAY:
                    //进一步解析，然后向服务器请求回放信息
                    break;
            }
        }
    }
}
